package hn.sigit.dao.hnd.cadastre;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import hn.sigit.dao.SigitDAO;
import hn.sigit.model.hnd.cadastre.HND_LandUse;

public class HND_LandUseDAO extends SigitDAO<HND_LandUse> {
	private static final long serialVersionUID = 1L;

	public static List<HND_LandUse> loadLandUsesByLevel(int level, boolean orderedByName) {
		return loadLandUsesByLevel(getSession(), level, orderedByName);
	}
	public static List<HND_LandUse> loadLandUsesByParent(HND_LandUse parent, boolean orderedByName) {
		return loadLandUsesByParent(getSession(), parent, orderedByName);
	}
	
	
	@SuppressWarnings("unchecked")
	public static List<HND_LandUse> loadLandUsesByLevel(Session session, int level, boolean orderedByName) {
		Criteria criteria = session.createCriteria(HND_LandUse.class);
		
		criteria.add(Restrictions.eq("level", level));
		if (orderedByName)
			criteria.addOrder(Order.asc("name"));
		
		return criteria.list();
	}
	@SuppressWarnings("unchecked")
	public static List<HND_LandUse> loadLandUsesByParent(Session session, HND_LandUse parent, boolean orderedByName) {
		Criteria criteria = session.createCriteria(HND_LandUse.class);
		
		criteria.add(Restrictions.eq("parent", parent));
		if (orderedByName)
			criteria.addOrder(Order.asc("name"));
		
		return criteria.list();
	}
}

